//
// Unihan Input Method
//
// Copyright © 2002-2007 Sun Wah Linux Ltd.
//
//
// This library is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as
// published by the Free Software Foundation; either version 2.1 of the
// License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
// USA
//
// $Id: ci.c 757 2007-05-10 08:19:31Z roger $
//

/* common iterface ci.c*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif

#include <stdio.h>
#include <common.h>

#include "ci.h"

void
symtab_init(UnihanIM *uim)
{
	TableDataPerDesktop *dd = (TableDataPerDesktop *)uim->desktopUserData;

	dd->numSut = 5;
	dd->sut = init_SymUserTable(dd->sut, dd->numSut);
}

char *
get_symbol(UnihanIM *uim, IMKeyEvent *kev)
{
	TableDataPerDesktop *dd = (TableDataPerDesktop *)uim->desktopUserData;
	SymbolUserTable * pSym = NULL;
	char *pChar = NULL;
#if DEBUG
	fprintf(stderr, "TABLE GET SYMBOL : numSut : %d\tmodifier : %x\tkeyCode : %x\n",
			dd->numSut, kev->modifier, kev->keyCode);
#endif
	pSym = get_SymUser(dd->sut, dd->numSut, kev->modifier, kev->keyCode);
	if (!pSym)
		return NULL;
	pChar = pSym->symbol;
	if (pChar)
		return pChar;
	else
		return NULL;
}

char *
get_word(UnihanIM *uim)
{
	TableDataPerDesktop *dd = (TableDataPerDesktop *)uim->desktopUserData;
	TableDataPerSession *ds = (TableDataPerSession *)uim->sessionUserData;
	WordUserTable *pWut = NULL;
	char *pChar = NULL;

#if DEBUG
	fprintf(stderr, "TABLE GET WORD : numWut : %d\tpreedit : %s\n",
			dd->numWut, ds->preedit);
#endif

	pWut = get_WordUser(dd->wut, dd->numWut, ds->preedit);
	if (!pWut)
		return NULL;
	pChar = pWut->word;
	if (pChar) {
#if DEBUG
		fprintf(stderr, "TABLE GET WORD : %s\n", pChar);
#endif
		return pChar;
	}
	else
		return NULL;
}


// vi:ts=4:nowrap:cin:expandtab
